<?php

declare(strict_types=1);

namespace app\model;

use app\admin\model\RsBrand;
use think\model\concern\SoftDelete;

/**
 * 
 *
 * @mixin \think\Model
 * @property int $id
 * @property string $supplier_name 供应商id
 * @property string $sku_id 外部商品id
 * @property string $image
 * @property string $goods_name 商品
 * @property string $brand_name 品牌
 * @property bool $sku_type 货源商品类型 1 卡券商品 2 直充商品
 * @property int $market_price 市场价
 * @property int $cost_price 成本价
 * @property int $sale_price 销售价
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at
 * @property int $order_id 订单编号
 * @property string $category_name 分类名称
 * @property int $goods_id 商户编号
 * @property int $quantity 数量
 * @property string $account 充值账号
 * @property string $api_ip 客服端ip
 * @property string $api_name 接口名称
 * @property int $brand_id 品牌id
 * @property int $category_id 商品分类id
 * @property string $brand_info 品牌的介绍
 * @property string $order_name 订单商品名称
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 */
class GoodsCart extends CommonModel
{
    use SoftDelete;

    /**
     *   新增商品信息关联订单.
     * **/
    public static function addGoods($good, $orderId, $supplier, $num, $account, $orderName)
    {
        $brand = RsBrand::where('id', $good['brand_id'])->find();
        $save['supplier_name'] = $supplier;
        $save['sku_id'] = $good['sku_id'];
        $save['image'] = $brand['brand_img'];
        $save['goods_name'] = $good['goods_name'];
        $save['brand_name'] = $brand['brand_name'];
        $save['category_name'] = RsRelate::getCate($good['brand_id']);
        $save['sku_type'] = $good['sku_type'];
        $save['market_price'] = $good['market_price'];
        $save['cost_price'] = $good['cost_price'];
        $save['sale_price'] = $good['sale_price'];
        $save['order_id'] = $orderId;
        $save['goods_id'] = $good->id;
        $save['quantity'] = $num;
        $save['account'] = $account;
        $save['api_name'] = $good['api_name'];
        $save['api_ip'] = request()->ip();
        $save['brand_id'] = $good['brand_id'];
        $save['category_id'] = $good['category_id'];
        $save['brand_info'] = $brand['brand_info'];
        $save['order_name'] = $orderName;
        $cart = new self();
        $cart->save($save);

        return $cart->id;
    }
}
